package DAO;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import Beans.ConfUpdate;
import Utils.HibernateUtil;



public class ConfUpdateDao {
	
	

	Transaction tr=null;
	private SessionFactory sessionFactory;
	
	/**
	 * 通过配置ID返回指定配置信息
	 * 
	 *            配置ID
	 * @return
	 */
	public ConfUpdate getConfUpdateById(int confUpdateId) {
		Session session = sessionFactory.openSession();
		tr = session.beginTransaction();
		ConfUpdate confUpdate = (ConfUpdate) session.get(ConfUpdate.class, confUpdateId);
		tr.commit();
		session.close();
		return confUpdate;
	}
	
	/**
	 * 删除配置
	 */
	public void delete(ConfUpdate confUpdate) {
		Session session = sessionFactory.openSession();
		tr = session.beginTransaction();
		session.delete(confUpdate);
		tr.commit();
		session.close();
	}
	
	/**
	 * 修改配置
	 */
	public void edit(ConfUpdate confUpdate) {
		Session session = sessionFactory.openSession();
		tr = session.beginTransaction();
		session.update(confUpdate);
		tr.commit();
		session.close();
	}
	
	
	public void save(ConfUpdate confUpdate){
		Session session=sessionFactory.openSession();
		tr=session.beginTransaction();
		session.save(confUpdate);
		tr.commit();
		session.close();
		
	}
	
	public List<ConfUpdate> getAll(){
		Session session=sessionFactory.openSession();
		tr=session.beginTransaction();
		Criteria c=session.createCriteria(ConfUpdate.class);
		List<ConfUpdate> confUpdates=c.list();
		tr.commit();
		session.close();
		return confUpdates;
	}
	
	public ConfUpdateDao() {
		sessionFactory=HibernateUtil.getSessionFactory();
	}
}
